package com.basic.library.binding.viewadapter.recyclerview;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.basic.library.base.BaseViewModel;
import com.basic.library.brvah.MBaseViewHolder;
import com.basic.library.brvah.MSimpleClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;

import me.tatarka.bindingcollectionadapter2.LayoutManagers;

/**
 * @author yj
 * @description
 */
public class EasyAdapterModel<T, K extends MBaseViewHolder> {
    public BaseQuickAdapter<T, K> adapter;
    public LayoutManagers.LayoutManagerFactory layoutManagerFactory;
    public ArrayList<T> initList;
    public MSimpleClickListener mSimpleClickListener;
    public BaseQuickAdapter.OnItemChildClickListener onItemChildClickListener;
    public BaseQuickAdapter.RequestLoadMoreListener loadMoreListener;
    public LineManagers.LineManagerFactory lineManagerFactory;
    public SwipeRefreshLayout.OnRefreshListener onRefreshListener;

    /**
     * mSimpleClickListener和onItemChildClickListener一般只需要一种，多了容易搞错
     * SwipeRefreshLayout的刷新监听和刷完框消失事件都写在MyBaseQuickAdapter里了
     */
    public EasyAdapterModel(BaseQuickAdapter<T, K> adapter,
                            ArrayList<T> initList,
                            LayoutManagers.LayoutManagerFactory layoutManagerFactory,
                            LineManagers.LineManagerFactory lineManagerFactory,
                            MSimpleClickListener mSimpleClickListener,
                            BaseQuickAdapter.OnItemChildClickListener onItemChildClickListener,
                            BaseViewModel baseViewModel) {
        this.adapter = adapter;
        this.initList = initList;
        this.layoutManagerFactory = layoutManagerFactory;
        this.lineManagerFactory = lineManagerFactory;
        this.mSimpleClickListener = mSimpleClickListener;
        this.onItemChildClickListener = onItemChildClickListener;
        if (baseViewModel instanceof BaseQuickAdapter.RequestLoadMoreListener)
            this.loadMoreListener = (BaseQuickAdapter.RequestLoadMoreListener) baseViewModel;
        if (baseViewModel instanceof SwipeRefreshLayout.OnRefreshListener)
            this.onRefreshListener = (SwipeRefreshLayout.OnRefreshListener) baseViewModel;
    }

    public EasyAdapterModel(BaseQuickAdapter<T, K> adapter,
                            ArrayList<T> initList,
                            LayoutManagers.LayoutManagerFactory layoutManagerFactory,
                            LineManagers.LineManagerFactory lineManagerFactory,
                            MSimpleClickListener mSimpleClickListener,
                            BaseQuickAdapter.OnItemChildClickListener onItemChildClickListener,
                            BaseQuickAdapter.RequestLoadMoreListener loadMoreListener,
                            SwipeRefreshLayout.OnRefreshListener onRefreshListener) {
        this.adapter = adapter;
        this.initList = initList;
        this.layoutManagerFactory = layoutManagerFactory;
        this.lineManagerFactory = lineManagerFactory;
        this.mSimpleClickListener = mSimpleClickListener;
        this.onItemChildClickListener = onItemChildClickListener;
        this.loadMoreListener = loadMoreListener;
        this.onRefreshListener = onRefreshListener;
    }
}
